package homework.polymorphic;

import java.util.Arrays;
import java.util.Comparator;

public class TestGraphic {
    public static void main(String[] args) {
        Graphic [] graphics = {new Circle(){{setRadius(5);}},
                              new Rectangle() {{ setLength(4); setWidth(6); }},
                              new Circle() {{ setRadius(3); }},
                              new Rectangle() {{ setLength(3); setWidth(3); }}
        };

        // 按照面积从小到大排序
        Arrays.sort(graphics, Comparator.comparingDouble(Graphic::area));

        // 输出排序后的图形信息
        for (Graphic graphic : graphics) {
            System.out.println(graphic.getInfo());
        }
    }
}
